dojo.provide('jetty.Request');

dojo.require('jetty.Location');

dojo.declare('jetty.Request', null, {
  constructor: function(request) {
    this.method    = ph.str(request.getMethod());
    this.http      = ph.str(request.getProtocol());
    this.secure    = request.isSecure() == true;
    this.location  = new jetty.Location(request);
    this.arguments = this._parseQueryString(this.location.search.replace(/^\?/, ''));
    this.headers   = {};
    
    var headers = request.getHeaderNames();
    while (headers.hasMoreElements()) {
      var header = headers.nextElement();
      this.headers[ph.str(header)] = ph.str(request.getHeader(header));
    }
  },
  
  _parseQueryString: function(qs) {
    var pairs = qs.split(/&/);
    var args  = {};
    for (var i = 0; i < pairs.length; i++) {
      var parts = pairs[i].split(/=/);
      args[parts[0]] = parts[1];
    }
    return args;
  }
});
